set (PACKAGE_BUGREPORT https://github.com/BYVoid/Opencc/issues)
set (OPENCC_VERSION_MAJOR 1)
set (OPENCC_VERSION_MINOR 0)
-set (OPENCC_VERSION_REVISION 3)
+set (OPENCC_VERSION_REVISION 4)
if (CMAKE_BUILD_TYPE MATCHES Debug)
set (version_suffix .Debug)
# limitations under the License.
#
+PREFIX = /usr
+
.PHONY: build clean node test xcode-build
build:
-DBUILD_DOCUMENTATION:BOOL=ON \
-DENABLE_GTEST:BOOL=OFF \
-DCMAKE_BUILD_TYPE=Release \
- -DCMAKE_INSTALL_PREFIX=/usr \
+ -DCMAKE_INSTALL_PREFIX=${PREFIX} \
../..)
- make -C build/rel VERBOSE=${VERBOSE}
+ make -C build/rel VERBOSE=${VERBOSE} PREFIX=${PREFIX}
package: build
make -C build/rel package_source VERBOSE=${VERBOSE}
+ make -C build/rel package_source VERBOSE=${VERBOSE} PREFIX=${PREFIX}
test:
mkdir -p build/dbg/root
rm -rf build xcode
install: build
- make -C build/rel install VERBOSE=${VERBOSE}
+ make -C build/rel install VERBOSE=${VERBOSE} PREFIX=${PREFIX}
# Change History of OpenCC
+## Version 1.0.4
+
+2016年4月1日
+
+* 使編譯時的腳本兼容Python 3。
+* 修正Visual C++ 2015的編譯問題。
+* 增補臺灣、香港地區用字用詞轉換。
+* 更新nan以修正Node.js擴展編譯兼容性問題。
+
## Version 1.0.3
2015年7月22日
* 嚴格審校一簡對多繁詞條,原則爲「能分則不合」。
* 支持中國大陸、臺灣、香港異體字和地區習慣用詞轉換,如「裏」「裡」、「鼠標」「滑鼠」。
* 詞庫和函數庫完全分離,可以自由修改、導入、擴展。
-* 支持C、C++、Python、PHP、Java、Ruby、Node.js。
+* 支持C、C++、Python、PHP、Java、Ruby、Node.js and Android。
* 兼容Windows、Linux、Mac平臺。
### Links 相關鏈接
### Build with CMake
-Linux/OSX (gcc 4.6 or clang 3.2 is required):
+Linux (gcc 4.6 is required):
```
make
sudo make install
```
+Mac OS X (clang 3.2 is required):
+
+```
+make PREFIX=/usr/local
+sudo make PREFIX=/usr/local install
+```
+
Windows MSYS:
```
make
```
-### Projects using Opencc 使用OpenCC的項目
+### iOS
+
+See https://github.com/gelosie/OpenCC/tree/master/iOS
+
+### Android
+
+See [android-opencc](https://github.com/qichuan/android-opencc)
+
+## Projects using Opencc 使用OpenCC的項目
* [ibus-pinyin](http://code.google.com/p/ibus/)
* [fcitx](http://code.google.com/p/fcitx/)
* [ibus-libpinyin](https://github.com/libpinyin/ibus-libpinyin)
* [BYVBlog](https://github.com/byvoid/byvblog)
* [豆瓣同城微信](http://weixinqiao.com/douban-event/)
+* [alfred-chinese-converter](https://github.com/amowu/alfred-chinese-converter)
+* [GoldenDict](https://github.com/goldendict/goldendict)
## License 許可協議
All these libraries are statically linked.
+## Change History 版本歷史
+
+https://github.com/BYVoid/OpenCC/blob/master/NEWS.md
+
## Contributors 貢獻者
* [BYVoid](http://www.byvoid.com/)
* [吕旭东](https://github.com/lvxudong)
* [Weng Xuetian](https://github.com/wengxt)
* [Ma Tao](https://github.com/iwater)
+* [Heinz Wiesinger](https://github.com/pprkut)
+* [J.W](https://github.com/jakwings)
+* [Amo Wu](https://github.com/amowu)
+* [Mark Tsai](https://github.com/mxgit1090)
+* [Zhe Wang](https://github.com/0x1997)
+* [sgqy](https://github.com/sgqy)
+* [Qichuan (Sean) ZHANG](https://github.com/qichuan)
+* [Flandre Scarlet](https://github.com/XadillaX)
+* [宋辰文](https://github.com/songchenwen)
+* [iwater](https://github.com/iwater)
+
+Please update this list you have contributed OpenCC.
膃 腽
臥 卧
臺 台
+菸 煙
蒕 蒀
蔥 葱
蔿 蒍
龚 龔
龛 龕
龟 龜
+鿎 䃮
+鿏 䥑
+鿒 鿓
+鿔 鎶
𠀾 𠁞
𠆲 儣
𠆿 𠌥
𫠒 鱆
𫠖 𩿅
𫠜 齯
+𬬭 錀
+𬬻 鑪
+𬭊 𨧀
+𬭛 𨨏
+𬭳 𨭎
+𬭶 𨭆
䁪 𥇢
䁻 䀥
䂎 𥎝
+䃮 鿎
䅐 𫀨
䅳 𫀬
䆉 𫁂
䤤 𫟺
䥄 𫠀
䥇 䦂
+䥑 鿏
䥗 𫔋
䥩 𨱖
䥯 𫔆
鋶 锍
鋸 锯
鋼 钢
+錀 𬬭
錁 锞
錂 𨱋
錄 录
鎲 镋
鎳 镍
鎵 镓
+鎶 鿔
鎷 𨰾
鎸 镌
鎿 镎
鑠 铄
鑣 镳
鑥 镥
+鑪 𬬻
鑭 镧
鑰 钥
鑱 镵
龭 𩨎
龯 𨱆
鿁 䜤
+鿓 鿒
𠁞 𠀾
𠌥 𠆿
𠏢 𠉗
𨥛 𨱀
𨥟 𫓫
𨦫 䦀
+𨧀 𬭊
𨧜 䦁
𨧰 𫟽
𨧱 𨱊
+𨨏 𬭛
𨨛 𫓼
𨨢 𫓿
𨩰 𫟾
𨪕 𫓮
𨫒 𨱐
𨬖 𫔏
+𨭆 𬭶
+𨭎 𬭳
𨭖 𫔑
𨭸 𫔐
𨮂 𨱕
內核 核心
內置 內建
內聯函數 行內函數
+全局 全域性
全角 全形
兼容 相容
冒泡排序 氣泡排序
+函數 函式
函數式編程 函數語言程式設計
刀片服務器 刀鋒伺服器
分佈式 分散式
+分區 分割槽
分辨率 解析度
刷新 重新整理
刻錄 燒錄
半角 半形
博客 部落格
卸載 解除安裝
+原代碼 原始碼
+參數 引數
參數表 參數列
句柄 控制代碼
可視化 視覺化
哈希 雜湊
單片機 微控制器
回調 回撥
+固件 韌體
圖像 影象
圖庫 相簿
圖標 圖示
在線 線上
地址 地址 位址
地址欄 位址列
-城域王 都會網路
+城域網 都會網路
+堆棧 堆疊
場效應管 場效電晶體
壁紙 桌布 壁紙
外置 外接
字庫 字型檔
字段 欄位
字符 字元
+字符串 字串
字符集 字符集
字節 位元組
字體 字型
存儲 儲存
存盤 存檔
+宏 巨集
宏內核 單核心
+寄存器 暫存器
密鑰 金鑰
實例 例項 實例
實模式 真實模式
導入 匯入
導出 匯出
局域網 區域網
+局部 區域性
屏幕 螢幕
屏蔽 遮蔽
嵌套 巢狀
+布爾 布林
帶寬 頻寬
引導程序 載入程式
彙編 彙編 組譯
打印 列印
打印機 印表機
打開 開啟 打開
+拋出 丟擲
持久性 永續性
+指針 指標
捲積 摺積
掃描儀 掃描器
掛斷 結束通話
採樣 取樣
採樣率 取樣率
接口 介面
-控件 控制項
+控件 控制元件
插件 外掛
搜索 搜尋
+操作數 運算元
操作系統 作業系統
擴展 擴充套件
擴展名 副檔名
查看 檢視
桌面型 桌上型
構造函數 建構函式
+標識符 識別符號
模塊 模組
模擬 模擬 類比
模擬電子 類比電子
死機 宕機
殺毒 防毒
比特 位元
+比特幣 比特幣
比特率 位元率
波分複用 波長分波多工
消息 訊息 消息
添加 新增
源代碼 原始碼
源文件 原始檔
+源碼 原始碼
溢出 溢位
演示文稿 簡報
激光 鐳射
組件 元件
綁定 繫結
網上鄰居 網路上的芳鄰
+網卡 網絡卡
網吧 網咖
網絡 網路
網關 閘道器
聯繫 聯絡
聯繫歷史 通話記錄
聲卡 音效卡
+聲明 宣告
脫機 離線
腳本 指令碼
自動轉屏 自動旋轉螢幕
藍牙 藍芽
虛函數 虛擬函式
虛擬機 虛擬機器
-表達式 表示式
+表達式 表示式 運算式
複印 影印
複選按鈕 覈取按鈕
複選框 覈取方塊
調用 呼叫
調色板 調色盤
調製解調器 數據機
-調試 偵錯
+調試 除錯 偵錯
調試器 偵錯程式
變量 變數
軟件 軟體
軟驅 軟碟機
通信 通訊
通訊卡 通話卡
+通配符 萬用字元
連接 連線
+連接器 聯結器
進制 進位制
進程 程序 進程
+運算符 運算子
運行 執行
過程式編程 程序式程式設計
遞歸 遞迴
音頻 音訊
頁眉 頁首
頁腳 頁尾
+項目 專案
+預處理器 前處理器
頭文件 標頭檔案
頻分多址 分頻多重進接
頻分複用 分頻多工
+類型 型別
類模板 類别範本
顯像管 映象管
顯卡 顯示卡
默認值 預設值
點擊 點選
鼠標 滑鼠
-比特幣 比特幣
肯尼亞 肯亞
莫桑比克 莫三比克
萊索托 賴索托
+萬象 永珍
蘇里南 蘇利南
貝寧 貝南
贊比亞 尚比亞
if len(sys.argv) != 3:
print("Find the value keyword in all pairs")
- print("Usage: ", sys.argv[0], "[input] [keyword]")
+ print(("Usage: ", sys.argv[0], "[input] [keyword]"))
exit(1)
find_target_items(sys.argv[1], sys.argv[2])
if len(sys.argv) < 4:
print("Merge and sort all text dictionaries")
- print("Usage: ", sys.argv[0], "[input1] [input2] ... [inputN] [output]")
+ print(("Usage: ", sys.argv[0], "[input1] [input2] ... [inputN] [output]"))
exit(1)
all_lines = []
if len(sys.argv) != 3:
print("Reverse key and value of all pairs")
- print("Usage: ", sys.argv[0], "[input] [output]")
+ print(("Usage: ", sys.argv[0], "[input] [output]"))
exit(1)
reverse_items(sys.argv[1], sys.argv[2])
if len(sys.argv) < 2:
print("Sort the dictionary")
- print("Usage: ", sys.argv[0], "[input] ([output])")
+ print(("Usage: ", sys.argv[0], "[input] ([output])"))
exit(1)
input = sys.argv[1]
if len(sys.argv) < 2:
print("Sort the dictionary")
- print("Usage: ", sys.argv[0], "[directory]")
+ print(("Usage: ", sys.argv[0], "[directory]"))
exit(1)
dirtectory = sys.argv[1]
#include <iostream>
-#include <node.h>
-#include <v8.h>
#include <nan.h>
#include "Config.hpp"
#include "Converter.hpp"
-using namespace v8;
using namespace opencc;
-string ToUtf8String(const Local<String>& str) {
- v8::String::Utf8Value utf8(str);
- return std::string(*utf8);
+string ToUtf8String(const v8::Local<v8::Value>& val) {
+ Nan::Utf8String utf8(val);
+ return string(*utf8);
}
-class OpenccBinding : public node::ObjectWrap {
+class OpenccBinding : public Nan::ObjectWrap {
struct ConvertRequest {
OpenccBinding* instance;
string input;
string output;
- Persistent<Function> callback;
+ Nan::Callback *callback;
Optional<opencc::Exception> ex;
ConvertRequest()
}
static NAN_METHOD(New) {
- NanScope();
OpenccBinding* instance;
try {
- if (args.Length() >= 1 && args[0]->IsString()) {
- string configFile = ToUtf8String(args[0]->ToString());
+ if (info.Length() >= 1 && info[0]->IsString()) {
+ string configFile = ToUtf8String(info[0]);
instance = new OpenccBinding(configFile);
} else {
instance = new OpenccBinding("s2t.json");
}
} catch (opencc::Exception& e) {
- NanThrowError(e.what());
- NanReturnUndefined();
+ Nan::ThrowError(e.what());
+ return;
}
- instance->Wrap(args.This());
- NanReturnValue(args.This());
+ instance->Wrap(info.This());
+ info.GetReturnValue().Set(info.This());
}
static NAN_METHOD(Convert) {
- NanScope();
- if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsFunction()) {
- NanThrowTypeError("Wrong arguments");
- NanReturnUndefined();
+ if (info.Length() < 2 || !info[0]->IsString() || !info[1]->IsFunction()) {
+ Nan::ThrowTypeError("Wrong arguments");
+ return;
}
ConvertRequest* conv_data = new ConvertRequest;
- conv_data->instance = ObjectWrap::Unwrap<OpenccBinding>(args.This());
- conv_data->input = ToUtf8String(args[0]->ToString());
- NanAssignPersistent(conv_data->callback, Local<Function>::Cast(args[1]));
+ conv_data->instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
+ conv_data->input = ToUtf8String(info[0]);
+ conv_data->callback = new Nan::Callback(info[1].As<v8::Function>());
conv_data->ex = Optional<opencc::Exception>::Null();
uv_work_t* req = new uv_work_t;
req->data = conv_data;
uv_queue_work(uv_default_loop(), req, DoConvert, (uv_after_work_cb)AfterConvert);
- NanReturnUndefined();
+ return;
}
static void DoConvert(uv_work_t* req) {
}
static void AfterConvert(uv_work_t* req) {
- NanScope();
+ Nan::HandleScope scope;
ConvertRequest* conv_data = static_cast<ConvertRequest*>(req->data);
- Local<Value> err = NanUndefined();
- Local<String> converted = NanNew<String>(conv_data->output.c_str());
+ v8::Local<v8::Value> err = Nan::Undefined();
+ v8::Local<v8::String> converted = Nan::New(conv_data->output.c_str()).ToLocalChecked();
if (!conv_data->ex.IsNull()) {
- err = NanNew<String>(conv_data->ex.Get().what());
+ err = Nan::New(conv_data->ex.Get().what()).ToLocalChecked();
}
const unsigned argc = 2;
- Local<Value> argv[argc] = {
+ v8::Local<v8::Value> argv[argc] = {
err,
- NanNew(converted)
+ converted
};
- NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(conv_data->callback), argc, argv);
+ conv_data->callback->Call(argc, argv);
delete conv_data;
delete req;
}
static NAN_METHOD(ConvertSync) {
- NanScope();
- if (args.Length() < 1 || !args[0]->IsString()) {
- NanThrowTypeError("Wrong arguments");
- NanReturnUndefined();
+ if (info.Length() < 1 || !info[0]->IsString()) {
+ Nan::ThrowTypeError("Wrong arguments");
+ return;
}
- OpenccBinding* instance = ObjectWrap::Unwrap<OpenccBinding>(args.This());
+ OpenccBinding* instance = Nan::ObjectWrap::Unwrap<OpenccBinding>(info.This());
- string input = ToUtf8String(args[0]->ToString());
+ string input = ToUtf8String(info[0]);
string output;
try {
output = instance->Convert(input);
} catch (opencc::Exception& e) {
- NanThrowError(e.what());
- NanReturnUndefined();
+ Nan::ThrowError(e.what());
+ return;
}
- Local<String> converted = NanNew<String>(output.c_str());
- NanReturnValue(converted);
+ v8::Local<v8::String> converted = Nan::New(output.c_str()).ToLocalChecked();
+ info.GetReturnValue().Set(converted);
}
- static void init(Handle<Object> target) {
- NanScope();
+ static NAN_MODULE_INIT(Init) {
// Prepare constructor template
- Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(OpenccBinding::New);
- tpl->SetClassName(NanNew<String>("Opencc"));
+ v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(OpenccBinding::New);
+ tpl->SetClassName(Nan::New("Opencc").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// Prototype
- NODE_SET_PROTOTYPE_METHOD(tpl, "convert", Convert);
- NODE_SET_PROTOTYPE_METHOD(tpl, "convertSync", ConvertSync);
+ Nan::SetPrototypeMethod(tpl, "convert", Convert);
+ Nan::SetPrototypeMethod(tpl, "convertSync", ConvertSync);
// Constructor
- target->Set(NanNew<String>("Opencc"), tpl->GetFunction());
+ v8::Local<v8::Function> cons = Nan::GetFunction(tpl).ToLocalChecked();
+ Nan::Set(target, Nan::New("Opencc").ToLocalChecked(), cons);
}
};
-void init(Handle<Object> target) {
- OpenccBinding::init(target);
-}
-
-NODE_MODULE(binding, init);
+NODE_MODULE(binding, OpenccBinding::Init);
{
"variables": {
- "opencc_version": "1.0.3"
+ "opencc_version": "1.0.4"
},
"target_defaults": {
"defines": [
{
"name": "opencc",
- "version": "1.0.3",
+ "version": "1.0.4",
"description": "Conversion between Traditional and Simplified Chinese",
"author": "BYVoid <byvoid@byvoid.com>",
"license": "Apache",
"Traditional Chinese"
],
"devDependencies": {
- "mocha": "1.8.1"
+ "mocha": "2.2.5"
},
"dependencies": {
- "nan": "^1.6.2"
+ "nan": "^2.2.0"
}
}
* limitations under the License.
*/
+#include <unordered_map>
+
#include "Config.hpp"
#include "ConversionChain.hpp"
#include "Converter.hpp"
#include "document.h"
-#include <unordered_map>
-
using namespace opencc;
typedef rapidjson::GenericValue<rapidjson::UTF8<char>> JSONValue;
std::ifstream ifs;
// Working directory
- ifs.open(fileName.c_str());
+ ifs.open(UTF8Util::GetPlatformString(fileName).c_str());
if (ifs.is_open()) {
return fileName;
}
// Package data directory
if (PACKAGE_DATA_DIRECTORY != "") {
string prefixedFileName = PACKAGE_DATA_DIRECTORY + fileName;
- ifs.open(prefixedFileName.c_str());
+ ifs.open(UTF8Util::GetPlatformString(prefixedFileName).c_str());
if (ifs.is_open()) {
return prefixedFileName;
}
prefixedFileName += ".json";
- ifs.open(prefixedFileName.c_str());
+ ifs.open(UTF8Util::GetPlatformString(prefixedFileName).c_str());
if (ifs.is_open()) {
return prefixedFileName;
}
ConverterPtr Config::NewFromFile(const string& fileName) {
ConfigInternal* impl = (ConfigInternal*)internal;
string prefixedFileName = impl->FindConfigFile(fileName);
- std::ifstream ifs(prefixedFileName);
+ std::ifstream ifs(UTF8Util::GetPlatformString(prefixedFileName));
string content(std::istreambuf_iterator<char>(ifs),
(std::istreambuf_iterator<char>()));
template <typename DICT>
static bool TryLoadFromFile(const string& fileName,
std::shared_ptr<DICT>* dict) {
- FILE* fp = fopen(fileName.c_str(), "rb");
+ FILE* fp =
+#ifdef _MSC_VER
+ // well, the 'GetPlatformString' shall return a 'wstring'
+ _wfopen(UTF8Util::GetPlatformString(fileName).c_str(), L"rb")
+#else
+ fopen(UTF8Util::GetPlatformString(fileName).c_str(), "rb")
+#endif // _MSC_VER
+ ;
+
if (fp == NULL) {
return false;
}
* limitations under the License.
*/
+#ifdef _MSC_VER
+#define NOMINMAX
+#include <Windows.h>
+#undef NOMINMAX
+#endif // _MSC_VER
+
#include "Config.hpp"
#include "Converter.hpp"
#include "opencc.h"
static string cError;
-opencc_t opencc_open(const char* configFileName) {
+opencc_t opencc_open_internal(const char* configFileName) {
try {
if (configFileName == nullptr) {
configFileName = OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD;
}
}
+#ifdef _MSC_VER
+opencc_t opencc_open_w(const wchar_t* configFileName) {
+ try {
+ if (configFileName == nullptr) {
+ return opencc_open_internal(nullptr);
+ }
+ std::string utf8fn = UTF8Util::U16ToU8(configFileName);
+ return opencc_open_internal(utf8fn.c_str());
+ } catch (std::runtime_error& ex) {
+ cError = ex.what();
+ return reinterpret_cast<opencc_t>(-1);
+ }
+}
+opencc_t opencc_open(const char* configFileName) {
+ if (configFileName == nullptr) {
+ return opencc_open_internal(nullptr);
+ }
+ std::wstring wFileName;
+ int convcnt = MultiByteToWideChar(CP_ACP, 0, configFileName, -1, NULL, 0);
+ if (convcnt > 0) {
+ wFileName.resize(convcnt);
+ MultiByteToWideChar(CP_ACP, 0, configFileName, -1, &wFileName[0], convcnt);
+ }
+ return opencc_open_w(wFileName.c_str());
+}
+#else
+opencc_t opencc_open(const char* configFileName) {
+ return opencc_open_internal(configFileName);
+}
+#endif
+
int opencc_close(opencc_t opencc) {
try {
SimpleConverter* instance = reinterpret_cast<SimpleConverter*>(opencc);
#pragma once
+#ifdef _MSC_VER
+#define NOMINMAX
+#include <Windows.h>
+#undef NOMINMAX
+#endif // _MSC_VER
+
#include "Common.hpp"
namespace opencc {
pstr = NextChar(pstr);
}
}
+
+#ifdef _MSC_VER
+ static std::wstring GetPlatformString(const std::string& str) {
+ return U8ToU16(str);
+ }
+#else
+ static std::string GetPlatformString(const std::string& str) {
+ return str;
+ }
+#endif // _MSC_VER
+
+
+#ifdef _MSC_VER
+ static std::string U16ToU8(const std::wstring& wstr) {
+ std::string ret;
+ int convcnt = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL);
+ if (convcnt > 0) {
+ ret.resize(convcnt);
+ WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), &ret[0], convcnt, NULL, NULL);
+ }
+ return ret;
+ }
+
+ static std::wstring U8ToU16(const std::string& str) {
+ std::wstring ret;
+ int convcnt = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
+ if (convcnt > 0) {
+ ret.resize(convcnt);
+ MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &ret[0], convcnt);
+ }
+ return ret;
+ }
+#endif // _MSC_VER
};
}
* @ingroup opencc_c_api
*/
OPENCC_EXPORT opencc_t opencc_open(const char* configFileName);
+#ifdef _MSC_VER
+/**
+* Makes an instance of opencc (wide char / Unicode)
+*
+* @param configFileName Location of configuration file. If this is set to NULL,
+* OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD will be loaded.
+* @return A description pointer of the newly allocated instance of
+* opencc. On error the return value will be (opencc_t) -1.
+* @ingroup opencc_c_api
+*/
+OPENCC_EXPORT opencc_t opencc_open_w(const wchar_t* configFileName);
+#endif /* _MSC_VER */
/**
* Destroys an instance of opencc